package com.blb.community.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.community.entity.ZyOwnerRoom;
import com.blb.community.entity.ZyOwnerRoomRecord;
import com.blb.community.entity.vo.ZyOwnerRoomVO;
import com.blb.community.mapper.ZyOwnerMapper;
import com.blb.community.mapper.ZyOwnerRoomMapper;
import com.blb.community.mapper.ZyOwnerRoomRecordMapper;
import com.blb.community.service.IZyOwnerRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;



/**
 * <p>
 * 房屋绑定表  服务实现类
 * </p>
 *
 * @author 帅帅
 * @since 2022-07-02
 */
@Service
public class ZyOwnerRoomServiceImpl extends ServiceImpl<ZyOwnerRoomMapper, ZyOwnerRoom> implements IZyOwnerRoomService {
    @Autowired
    private ZyOwnerMapper zyOwnerMapper;


    @Override
    public IPage<List<ZyOwnerRoomVO>> getZyOwnerRoomList(ZyOwnerRoomVO zyOwnerRoomVO) {
        Page<ZyOwnerRoom> zyOwnerRoomPage = new Page<>(zyOwnerRoomVO.getPageCount(), zyOwnerRoomVO.getPageSize());
        zyOwnerRoomPage.setOptimizeJoinOfCountSql(false);
        IPage<List<ZyOwnerRoomVO>> zyOwnerRoomList = zyOwnerMapper.getZyOwnerRoomList(zyOwnerRoomVO, zyOwnerRoomPage);
        return zyOwnerRoomList;
    }
    @Autowired
    private ZyOwnerRoomMapper zyOwnerRoomMapper;

    @Autowired
    private ZyOwnerRoomRecordMapper zyOwnerRoomRecordMapper;
    @Override
    public void updateStatusOwner(String id) {
        zyOwnerRoomMapper.updateStatusOwner(id);
        ZyOwnerRoom byOwnerRoomId = zyOwnerRoomMapper.getByOwnerRoomId(id);
        System.out.println(byOwnerRoomId);
        ZyOwnerRoomRecord zyOwnerRoomRecord = new ZyOwnerRoomRecord();
        zyOwnerRoomRecord.setOwnerRoomId(byOwnerRoomId.getOwnerRoomId());
        zyOwnerRoomRecord.setCommunityId(byOwnerRoomId.getCommunityId());
        zyOwnerRoomRecord.setBuildingId(byOwnerRoomId.getBuildingId());
        zyOwnerRoomRecord.setUnitId(byOwnerRoomId.getUnitId());
        zyOwnerRoomRecord.setRoomId(byOwnerRoomId.getRoomId());
        zyOwnerRoomRecord.setOwnerId(byOwnerRoomId.getOwnerId());
        zyOwnerRoomRecord.setOwnerType(byOwnerRoomId.getOwnerType());
        zyOwnerRoomRecord.setRoomStatus(byOwnerRoomId.getRoomStatus());
        zyOwnerRoomRecord.setCreateBy(byOwnerRoomId.getCreateBy());
        zyOwnerRoomRecord.setCreateTime(byOwnerRoomId.getCreateTime());
        zyOwnerRoomRecord.setUpdateBy(byOwnerRoomId.getUpdateBy());
        zyOwnerRoomRecord.setUpdateTime(LocalDateTime.now());
        zyOwnerRoomRecord.setRemark(byOwnerRoomId.getRemark());
      //  zyOwnerRoomRecordMapper.insertRoomRecords(zyOwnerRoomRecord);
        zyOwnerRoomRecordMapper.insert(zyOwnerRoomRecord);
    }

    @Override
    public void delByOwnerId(Long id) {
        zyOwnerRoomMapper.delByOwnerId(id);
    }
}
